/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.google.code.jmarias.client;

import com.google.code.jmarias.client.tcp.ClientSimulator;
import java.awt.Font;
import org.apache.commons.logging.LogFactory;
import org.newdawn.slick.Color;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.TrueTypeFont;
import org.newdawn.slick.geom.Vector2f;
import org.newdawn.slick.util.Log;

/**
 *
 * @author bart
 */
public class Globals {

    /** Cesta k obrazkum pouzivanych ke hre */
    private final String RESPATH = "/src/main/resources/";
    private final String IMGPATH = RESPATH + "img/";

    /* ID jednotlivych obrazovek hry */
    private final int MAINMENUSTATE = 0;
    private final int GAMESTATE = 1;

    /* Defaultni rozliseni */
    private static int screenWidth = 800;
    private static int screenHeight = 600;
    /** Prepinac fullscreenu */
    private static boolean fullscreen = false;

    /* Definice promennych pro fonty */
    /** Stredni pismo */
    protected Font font = null;
    protected TrueTypeFont trueFont = null;

    /** Velke pismo */
    protected Font fontBig = null;
    protected TrueTypeFont trueFontBig = null;

    /** Male pismo */
    protected Font fontSmall = null;
    protected TrueTypeFont trueFontSmall = null;

    /** ID aktualne vybraneho prvku (tlacitka) **/
    private int hoverID = 0;


    /* Globalni meritko. Prepocitava se defaultniho 800x600 rozliseni. */
    private Vector2f globalScale;

    public Globals() throws SlickException {
        System.out.println("Inicializace globalnich promennych");

        // Vypocet globalniho meritka, pomerem k defaultnimu rozliseni 800x600.
        globalScale = new Vector2f( screenWidth / 800f, screenHeight/ 600f);
        
    }


    public void loadFonts() {
        /* Inicicializace jednotlivych velikosti a rezu pisma */
        font = new Font("sansserif", Font.PLAIN, 16);
        trueFont = new TrueTypeFont(font, true);

        fontBig = new Font("sansserif", Font.BOLD, 25);
        trueFontBig = new TrueTypeFont(fontBig, true);

        fontSmall = new Font("sansserif", Font.PLAIN, 13);
        trueFontSmall = new TrueTypeFont(fontSmall, true);

    }
    

    public int getGAMESTATE() {
        return GAMESTATE;
    }

    public int getMAINMENUSTATE() {
        return MAINMENUSTATE;
    }

    public String getIMGPATH() {
        return IMGPATH;
    }

    public String getRESPATH() {
        return RESPATH;
    }

    public Vector2f getGlobalScale() {
        return globalScale;
    }

    public int getScreenHeight() {
        return screenHeight;
    }

    public int getScreenWidth() {
        return screenWidth;
    }

    public boolean isFullscreen() {
        return fullscreen;
    }

    public int getHoverID() {
        return hoverID;
    }

    public void setHoverID(int hoverID) {
        this.hoverID = hoverID;
    }

    

    /**
     * Vykresli text na danou pozici.
     *
     * @param size Textovy popisek velikost pisma. {"small", "normal", "big"}
     * @param position Pozice textu
     * @param color Barva textu. (napr. Color.white)
     * @param text Text samotny.
     */
    public void printText(String size, Vector2f tmpPosition, Color color, String text) {
        Vector2f position = new Vector2f(tmpPosition);

        if(size == null || position == null || color == null || text == null)
               return;


        if(size.equals("big")) {
            trueFontBig.drawString(position.x, position.y, text, color);
        } else if(size.equals("normal")) {
            trueFont.drawString(position.x, position.y, text, color);
        } else if(size.equals("small")) {
            trueFontSmall.drawString(position.x, position.y, text, color);
        }

    }
    
    /**
     * Vykresli text na danou pozici. Navic umi vertikalni i horizontalni zarovnani textu.
     *
     * @param size Textovy popisek velikost pisma. {"small", "normal", "big"}
     * @param position Pozice textu
     * @param color Barva textu. (napr. Color.white)
     * @param text Text samotny.
     * @param valign Vertikalni zarovnani textu. {"top", "middle", "bottom"}
     * @param align Horizontalni zarovnani. {"left", "center", "top"}
     */
    public void printText(String size, Vector2f tmpPosition, Color color, String text, String valign, String align) {

        Vector2f textPosition = new Vector2f();
        textPosition.equals(tmpPosition);
        TrueTypeFont textFont = null;

        if(size == null || textPosition == null || color == null || text == null)
               return;
        

        // Nastavi velikost textu
        if(size.equals("big")) {
            textFont = trueFontBig;
        } else if(size.equals("normal")) {
            textFont = trueFont;
        } else if(size.equals("small")) {
            textFont = trueFontSmall;
        }


        // Vertikalni zarovnani
        if(valign.equals("middle"))
            textPosition.y = tmpPosition.y - Math.round((float) textFont.getHeight(text) / 2);
        else if(valign.equals("bottom"))
            textPosition.y = tmpPosition.y - textFont.getHeight(text);


        // Horizontalni zarovnani
        if(align.equals("center"))
            textPosition.x = tmpPosition.x - Math.round((float) textFont.getWidth(text) / 2f);
        else if(align.equals("right"))
            textPosition.x = tmpPosition.x - textFont.getWidth(text);

        // Vykresleni textu
        textFont.drawString(textPosition.x, textPosition.y, text, color);
    }

}
